package main

import (
	"gitee.com/dennis-mxx/mxx-core-v2/minit"
	"gitee.com/dennis-mxx/mxx-core-v2/mlogger"
	"gitee.com/dennis-mxx/mxx-core-v2/mmodel"
	"gitee.com/dennis-mxx/mxx-core-v2/mweb"
	"github.com/gin-gonic/gin"
)

func main() {

	minit.InitializeCmd("dev", nil)

	mweb.Engine.OPTIONS("/", func(context *gin.Context) {
		origin := context.GetHeader("Origin")
		context.Header("Access-Control-Allow-Origin", origin)                                                                                                                          // 注意这一行，不能配置为通配符“*”号
		context.Header("Access-Control-Allow-Credentials", "true")                                                                                                                     // 注意这一行，必须设定为 true
		context.Header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers,Cookie, Origin, X-Requested-With, Content-Type, Accept, Authorization, Token, Timestamp, UserId") // 我们自定义的header字段都需要在这里声明
		context.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
		context.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type,cache-control")
		context.AbortWithStatus(200)
	})

	mweb.Engine.UseMiddleware()
	mweb.Engine.Use(func(ctx *gin.Context) {
		if ctx.Writer.Status() == 404 {
			ctx.JSON(404, &mmodel.Resp{Message: "PATH NOT FOUND", Code: 404})
		}
		ctx.Next()
	})
	mweb.Engine.XXGet("/list", func(stx mweb.SessionCtx, ctx *gin.Context) (result any, err error) {
		select {
		case <-ctx.Done():
			break
		}

		return mmodel.Ok(), nil
	})
	mweb.Engine.GET("/stop", func(context *gin.Context) {

	})

	err := mweb.Engine.XXRun()
	if err != nil {
		mlogger.Out.Error("gin run failure , ", err)
	}
}
